package Help;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.TitledBorder;
import javax.swing.GroupLayout;
import java.util.EventObject;
import java.util.Date;
import com.toedter.calendar.JDateChooser;
import java.text.SimpleDateFormat;
import java.sql.*;
import java.text.*;
import javax.swing.JTable.*;
import java.awt.print.*;
import java.beans.*;
import java.net.*;
import java.io.*;


public class HelpPanel extends JPanel implements ActionListener
{
	private JPanel basePanel = null,centerPanel = null;
	private JEditorPane helpJEP = null;
	private JScrollPane helpJSP = null;
	private Box buttonBox = null;
	private JButton rentBut = null,returnBut = null,bookBut = null,addClientBut = null,editClientBut = null,
	                addEmployeeBut = null,editEmployeeBut = null,addStockBut = null,editStockBut = null,
	                advancedSettingsBut = null,reportsBut = null,accessLevelControllBut = null;
	                
	private URL fileURL = null;              
	                
	//Fonts and colours
	private Font butFont = null;
	
	public HelpPanel()
	{
		//colours & fonts
	    butFont = new Font("ButtonFont",Font.BOLD,15);
		
		//constructing Buttons
		rentBut = new JButton("<html><U>RENTALS<U><html>");
		returnBut = new JButton("<html><U>RETURNS<U><html>");
		bookBut = new JButton("<html><U>BOOKINGS<U><html>");
		addClientBut = new JButton("<html><U>ADDING CLIENTS<U><html>");
		editClientBut = new JButton("<html><U>EDITING CLIENTS<U><html>");
		addEmployeeBut = new JButton("<html><U>ADDING EMPLOYEES<U><html>");
		editEmployeeBut = new JButton("<html><U>EDITING EMPLOYEES<U><html>");
		addStockBut = new JButton("<html><U>ADDING STOCK<U><html>");
		editStockBut = new JButton("<html><U>EDITING STOCK<U><html>");
		advancedSettingsBut = new JButton("<html><U>ADVANCED SETTINGS<U><html>");
		reportsBut = new JButton("<html><U>REPORTS<U><html>");
		accessLevelControllBut = new JButton("<html><U>ACCESS LEVELS<U><html>");
		
		//Appearance Of buttons
		rentBut.setForeground(Color.blue);
		returnBut.setForeground(Color.blue);
		bookBut.setForeground(Color.blue);
		addClientBut.setForeground(Color.blue);
		editClientBut.setForeground(Color.blue);
		addEmployeeBut.setForeground(Color.blue);
		editEmployeeBut.setForeground(Color.blue);
		addStockBut.setForeground(Color.blue);
		editStockBut.setForeground(Color.blue);
		advancedSettingsBut.setForeground(Color.blue);
		reportsBut.setForeground(Color.blue);
		accessLevelControllBut.setForeground(Color.blue);

		//removingBorders
		rentBut.setBackground(new Color(238,238,238));
		rentBut.setBorderPainted(false);
		rentBut.setFocusPainted(false);
		returnBut.setBackground(new Color(238,238,238));
		returnBut.setBorderPainted(false);
		returnBut.setFocusPainted(false);
		bookBut.setBackground(new Color(238,238,238));
		bookBut.setBorderPainted(false);
		bookBut.setFocusPainted(false);
		addClientBut.setBackground(new Color(238,238,238));
		addClientBut.setBorderPainted(false);
		addClientBut.setFocusPainted(false);
		editClientBut.setBackground(new Color(238,238,238));
		editClientBut.setBorderPainted(false);
		editClientBut.setFocusPainted(false);
		addEmployeeBut.setBackground(new Color(238,238,238));
		addEmployeeBut.setBorderPainted(false);
		addEmployeeBut.setFocusPainted(false);
		editEmployeeBut.setBackground(new Color(238,238,238));
		editEmployeeBut.setBorderPainted(false);
		editEmployeeBut.setFocusPainted(false);
		addStockBut.setBackground(new Color(238,238,238));
		addStockBut.setBorderPainted(false);
		addStockBut.setFocusPainted(false);
		editStockBut.setBackground(new Color(238,238,238));
		editStockBut.setBorderPainted(false);
		editStockBut.setFocusPainted(false);
		advancedSettingsBut.setBackground(new Color(238,238,238));
		advancedSettingsBut.setBorderPainted(false);
		advancedSettingsBut.setFocusPainted(false);
		reportsBut.setBackground(new Color(238,238,238));
		reportsBut.setBorderPainted(false);
		reportsBut.setFocusPainted(false);
		accessLevelControllBut.setBackground(new Color(238,238,238));
		accessLevelControllBut.setBorderPainted(false);
		accessLevelControllBut.setFocusPainted(false);
		
		
		//actionListeners Of Buttons
		rentBut.addActionListener(this);
		returnBut.addActionListener(this);
		bookBut.addActionListener(this);
		addClientBut.addActionListener(this);
		editClientBut.addActionListener(this);
		addEmployeeBut.addActionListener(this);
		editEmployeeBut.addActionListener(this);
		addStockBut.addActionListener(this);
		editStockBut.addActionListener(this);
		advancedSettingsBut.addActionListener(this);
		reportsBut.addActionListener(this);
		accessLevelControllBut.addActionListener(this);
		
		buttonBox = new Box(BoxLayout.Y_AXIS);
		buttonBox.add(Box.createVerticalStrut(5));
		buttonBox.add(rentBut);	
		buttonBox.add(returnBut);
		buttonBox.add(bookBut);
		buttonBox.add(Box.createVerticalStrut(15));
		buttonBox.add(addClientBut);
		buttonBox.add(editClientBut);
		buttonBox.add(Box.createVerticalStrut(15));
		buttonBox.add(addEmployeeBut);
		buttonBox.add(editEmployeeBut);
		buttonBox.add(Box.createVerticalStrut(15));
		buttonBox.add(addStockBut);
		buttonBox.add(editStockBut);
		buttonBox.add(Box.createVerticalStrut(18));
		buttonBox.add(advancedSettingsBut);
		buttonBox.add(Box.createVerticalStrut(3));
		buttonBox.add(reportsBut);
		buttonBox.add(Box.createVerticalStrut(3));
		buttonBox.add(accessLevelControllBut);
		buttonBox.add(Box.createVerticalStrut(3));
		buttonBox.setBorder(BorderFactory.createRaisedBevelBorder());
		
		helpJEP = new JEditorPane();
		helpJEP.setContentType("text/html");
		helpJEP.setEditable(false);
		//helpJEP.setLineWrap(true);
		//helpJEP.setWrapStyleWord(true);
		helpJSP = new JScrollPane(helpJEP,ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		centerPanel = new JPanel(new GridLayout(1,1));
		centerPanel.add(helpJSP);
		centerPanel.setBorder(BorderFactory.createLoweredBevelBorder());
		
		basePanel = new JPanel(new BorderLayout());
		basePanel.add(centerPanel,BorderLayout.CENTER);
		basePanel.add(buttonBox,BorderLayout.WEST);
		
		this.setLayout(new GridLayout(1,1));
		this.add(basePanel);
	}
	
	public void actionPerformed(ActionEvent ae)
	{
		Object source = ae.getSource();
		
		if(source == rentBut)
		{
			setHelpPages("rent.html");
		}
		if(source == returnBut)
		{
			setHelpPages("return.html");
		}
		if(source == bookBut)
		{
			setHelpPages("book.html");
		}
		if(source == addClientBut)
		{
			setHelpPages("addClient.html");
		}
		if(source == editClientBut)
		{
			setHelpPages("editClient.html");
		}
		if(source == addEmployeeBut)
		{
			setHelpPages("addEmployee.html");
		}
		if(source == editEmployeeBut)
		{
			setHelpPages("editEmployee.html");
		}
		if(source == addStockBut)
		{
			setHelpPages("addStockItem.html");
		}
		if(source == editStockBut)
		{
			setHelpPages("editStockItem.html");
		}
		if(source == advancedSettingsBut)
		{
			setHelpPages("advancedSettings.html");
		}
		if(source == reportsBut)
		{
			setHelpPages("reports.html");
		}
		if(source == accessLevelControllBut)
		{
			setHelpPages("accessLevel.html");
		}
	}
	
	public void setHelpPages(String fileName)
	{
		String filePath = "file:///c:/loanTurtle/helpFiles/";
		try
		{
			fileURL = new URL(filePath + fileName);
			helpJEP.setPage(fileURL);
		}
		catch(MalformedURLException mfe)	
		{
			mfe.printStackTrace();
		}
		catch(IOException ioe)
		{
			ioe.printStackTrace();
		}
	}
	
}